<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
	<button>主线程执行</button>
	<button>使用分线程执行</button>
	<button>假死状态</button>
</body>
<script>
	const btns = document.querySelectorAll("button");
	btns[0].onclick = function(){
		let num = 0;
		console.log("开始计算：")
		for(let i=0;i<200000000;i++){
			num+=Math.random();
		}
		console.log("计算完毕：",num)
	}
	btns[1].onclick = function(){
		if(typeof Worker === "undefined"){
			console.log("不支持分线程！");
		}else{
			const w = new Worker("./lib/my.js");
			w.postMessage(50000000);
			w.onmessage = function(e){
				console.log("主线程接收计算结果",e.data);
			}
		}
		
	}
	btns[2].onclick = function(){
		console.log(this.innerText);
	}
</script>
</html>